package org.hawk.gwtppc.webtest.tests.constructorsuite;

import java.lang.reflect.Constructor;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.List;

import org.hawk.gwtppc.webtest.common.Asserts;
import org.hawk.gwtppc.webtest.common.Test;
import org.hawk.gwtppc.webtest.tests.mock.GenericClassMock;
import org.hawk.gwtppc.webtest.tests.mock.SubClassMock2;

public class GetGenericParameterTypesTest implements Test {

	@SuppressWarnings("rawtypes")
	public void run() throws Throwable {
		Asserts.assertTrue(Arrays.equals(SubClassMock2.class.getDeclaredConstructor(String.class).getGenericParameterTypes(),  
				new Class[]{ String.class }));
		
		Constructor<GenericClassMock> c = GenericClassMock.class.getDeclaredConstructor(List.class, CharSequence.class, Object.class, Object.class);
		Type[] params = c.getGenericParameterTypes();
		Asserts.assertEquals(params.length,  4);
		
		Asserts.assertTrue(params[0] instanceof TypeVariable);
		TypeVariable<?> tv = (TypeVariable<?>)params[0];
		Asserts.assertEquals(tv.getName(),  "J");
		Asserts.assertEquals(tv.getGenericDeclaration(), c);
		
		Asserts.assertTrue(params[1] instanceof TypeVariable);
		tv = (TypeVariable<?>)params[1];
		Asserts.assertEquals(tv.getName(),  "X1");
		Asserts.assertEquals(tv.getGenericDeclaration(), GenericClassMock.class);
		
		Asserts.assertTrue(params[2] instanceof TypeVariable);
		tv = (TypeVariable<?>)params[2];
		Asserts.assertEquals(tv.getName(),  "X2");
		Asserts.assertEquals(tv.getGenericDeclaration(), GenericClassMock.class);
		
		Asserts.assertTrue(params[3] instanceof TypeVariable);
		tv = (TypeVariable<?>)params[3];
		Asserts.assertEquals(tv.getName(),  "X3");
		Asserts.assertEquals(tv.getGenericDeclaration(), GenericClassMock.class);
	}

	public String getName() {
		return "getGenericParameterTypes()";
	}

}
